package com.ethannhu.todaynews.activity

import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import androidx.activity.enableEdgeToEdge
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.viewbinding.ViewBinding
import com.ethannhu.todaynews.util.ReflectUtil

/**
 * 通用ViewModel Activity
 * 包括封装ViewBinding，主要是处理每次要setContentView
 * 以及自动创建ViewModel
 * 以及viewModel的通用观察处理
 */
open class BaseViewModelActivity<T : ViewBinding> : BaseLogicActivity() {
    lateinit var binding: T
    protected open val enableInset: Boolean = true

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ReflectUtil.newViewBinding(layoutInflater, javaClass)

        setContentView(binding.root)
        enableEdgeToEdge()

        // 设置偏移，会导致无法沉浸式
        if (enableInset) {
            ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, insets ->
                val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
                v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
                insets
            }
        }


    }

}